package org.system.core.common;

import com.github.pagehelper.PageInfo;
import lombok.Data;
import org.system.core.enums.ResultCodeEnum;

import java.util.List;

/**
 * @author baoRoot
 * @param <T>
 */
@Data
public class PageResult<T> {
    private Integer code;
    private String message;
    private List<T> data;
    private Long total;

    public PageResult() {}

    public PageResult(final Integer code, final String message, final List<T> data, final Long total) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.total = total;
    }

    public static <T> PageResult<T> ok(PageInfo<T> pageInfo) {
        PageResult<T> pageInfoResult = new PageResult<>();
        pageInfoResult.setCode(ResultCodeEnum.SUCCESS.getCode());
        pageInfoResult.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        pageInfoResult.setTotal(pageInfo.getTotal());
        pageInfoResult.setData(pageInfo.getList());
        return pageInfoResult;
    }
}
